<?php
/**
 * Created by PhpStorm.
 * User: 小蛮哼哼哼
 * Email: 243194993@qq.com
 * Date: 2022/1/5 0005
 * Time: 18:02
 * motto: 现在的努力是为了小时候吹过的牛逼！
 */

declare(strict_types=1);

namespace app\common\business;
use app\common\model\MemberPaylog as ModelObj;
use think\Exception;

class MemberPaylog extends Base
{
    /**
     * @var ModelObj
     */
    protected ModelObj $modelObj;

    /**
     *
     */
    public function __construct()
    {
        $this->modelObj = new ModelObj();
    }

    public function getByOrderId($ordersn){
        try{
            $info =$this->modelObj->getModelByInfo([['ordersn','=',$ordersn]],'*');
        }catch (\Exception $e){
            throw new Exception($e->getMessage());
        }

        return $info;
    }

    /**
     * 指定订单与类型
     * @param $order_id
     * @param $type
     * @return array|\think\Model|null
     * @throws Exception
     */
    public function getByOrderTypeId($order_id,$type=2,$status=1){
        try{
            $info =$this->modelObj->getModelByInfo([['order_id','=',$order_id],['type','=',$type],['status','=',$status]],'*');
        }catch (\Exception $e){
            throw new Exception($e->getMessage());
        }
        return $info;
    }

    public function getByLogId($id){
        try{
            $info =$this->modelObj->getModelByInfo([['id','=',$id]],'*');
        }catch (\Exception $e){
            throw new Exception($e->getMessage());
        }
        return $info;
    }

    /**
     * 指定订单与类型
     * @param $order_id
     * @param $type
     * @return array|\think\Model|null
     * @throws Exception
     */
    public function getByOrderTypeIdNoPay($order_id,$type=2,$openid){
        try{
            $info =$this->modelObj->getModelByInfo([['order_id','=',$order_id],['type','=',$type],['status','=',0],['openid','=',$openid]],'*');
        }catch (\Exception $e){
            throw new Exception($e->getMessage());
        }
        return $info;
    }

    /**
     * 查询已支付的保证金记录
     * @param $type
     * @param $openid
     * @return array|\think\Model|null
     * @throws Exception
     */
    public function getByBzjType($type=6,$openid){
        try{
            $info =$this->modelObj->getModelByInfo([['type','=',$type],['status','=',1],['openid','=',$openid]],'*');
        }catch (\Exception $e){
            throw new Exception($e->getMessage());
        }
        return $info;
    }


    /**
     * 新增编辑支付记录
     * @param $data
     * @return bool
     * @throws Exception
     */
    public function saveData($data){

        try{
            $info =$this->modelObj->getModelByInfo([['id','=',$data['id']]],'*');
        }catch (\Exception $e){
            throw new Exception($e->getMessage());
        }
        if($info){
            $info->save($data);
        }else{
            $this->modelObj->save($data);
        }
        return true;
    }
}